#!/usr/bin/php -d mysqlnd.net_read_timeout=3600
<?php
set_include_path("../../../include");
require("header.inc.php");

$startShard = !empty($argv[1]) ? $argv[1] : 1;
$shardIDs = Zotero_DB::columnQuery("SELECT shardID FROM shards WHERE shardID >= ? ORDER BY shardID", $startShard);

foreach ($shardIDs as $shardID) {
	echo "Shard: $shardID\n";
	
	Zotero_Admin_DB::query("CREATE TABLE `deletedCollections` (`collectionID` int(10) unsigned NOT NULL, `dateDeleted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`collectionID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8", false, $shardID);
	Zotero_Admin_DB::query("ALTER TABLE `deletedCollections` ADD CONSTRAINT `deletedCollections_ibfk_1` FOREIGN KEY (`collectionID`) REFERENCES `collections` (`collectionID`) ON DELETE CASCADE", false, $shardID);
	Zotero_Admin_DB::query("CREATE TABLE `deletedSearches` (`searchID` int(10) unsigned NOT NULL, `dateDeleted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`searchID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8", false, $shardID);
	Zotero_Admin_DB::query("ALTER TABLE `deletedSearches` ADD CONSTRAINT `deletedSearches_ibfk_1` FOREIGN KEY (`searchID`) REFERENCES `savedSearches` (`searchID`) ON DELETE CASCADE", false, $shardID);
}
